package com.lms.logisticsmanagementsystem.config;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TableSplit {

   public Map<String,Object> tableFormat(Integer page, Integer limit, List list){
        Map<String,Object> map = new HashMap<>();
        List curList = new ArrayList();
        //当前数据索引
        Integer curIndex = (page-1)*limit;
        //目标数据索引
        Integer tarIndex = curIndex+limit;
        //数据总数
        Integer total = list.size();
        //如果目标行索引大于数据总数，则返回数据总数进行判断
        if (tarIndex > total) {
            tarIndex = total;
        }
        for (int i = curIndex; i < tarIndex; i++) {
            curList.add(list.get(i));
        }
        map.put("code", "0");
        map.put("msg", "");
        map.put("count", list.size());
        map.put("data", curList);
        System.out.println(map);
        return map;
    }
}
